package gyb.rasa.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import gyb.rasa.entity.User;
import gyb.rasa.entity.Video;
import gyb.rasa.entity.vo.Department;
import gyb.rasa.mapper.VideoMapper;
import gyb.rasa.service.VideoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 郜宇博
 * @since 2023-04-11
 */
@Service
public class VideoServiceImpl extends ServiceImpl<VideoMapper, Video> implements VideoService {

    /**
     * 获取指定疾病种类的视频
     *
     * @param disease 疾病种类
     * @return 疾病视频
     */
    @Override
    public List<Video> getVideosByDisease(String disease) {
        List<Video> videoList = baseMapper.selectList(new QueryWrapper<Video>().eq("disease", disease));
        return videoList;
    }

    /**
     * 获取指定ID的视频
     *
     * @param vid vid
     * @return Video
     */
    @Override
    public Video getVideosByVid(String vid) {
        return baseMapper.selectById(vid);
    }

    /**
     * 获取科、疾病二级列表
     *
     * @return
     */
    @Override
    public List<Department> getDepartmentsWithDisease() {

        List<Department> result = new ArrayList<>();
        //childResult.get()
        List<Object> distinctDepartment = baseMapper.selectObjs(new QueryWrapper<Video>().select("Distinct department"));
        for (Object department : distinctDepartment) {
            List<Object> diseases = baseMapper.selectObjs(new QueryWrapper<Video>().eq("department", department).select("Distinct disease"));
            Department department1 = new Department(diseases,(String) department);
            result.add(department1);
        }
        return result;
    }
}
